/*
 * @Description:
 * @Version:
 * @Autor: kkz <keke.zhang@seaboxdata.com>
 * @Date: 2024-03-06 17:55:23
 * @LastEditors: kkz
 * @LastEditTime: 2024-03-25 14:57:15
 */
import { createRouter, createWebHistory } from 'vue-router'
//createRouter 创建路由实例
//配置 history 模式
//1,createWebHistory   地址栏不带 # 号

const router = createRouter({
  //wite 中的环境变量
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login',
      component: () => import('@/views/login/LoginPage.vue'),
      children: [
        {
          path: '/login',
          component: () => import('@/views/login/LoginPage.vue')
        }
      ]
    }, //登录页
    {
      path: '/article/manage',
      component: () => import('@/views/layout/LayoutContainer.vue'),
      redirect: '/article/manage',
      children: [
        {
          path: '/article/manage',
          component: () => import('@/views/article/ArticleManage.vue')
        },
        {
          path: '/article/channel',
          component: () => import('@/views/article/ArticleChannel.vue')
        },
        {
          path: '/workbench',
          component: () => import('@/views/workbench/workbench.vue')
        },
        {
          path: '/wagesdetail',
          component: () => import('@/views/wagesDetail/wagesdetail.vue')
        },
        {
          path: '/attendance',
          component: () => import('@/views/attendance/attendance.vue')
        },
        {
          path: '/user/profile',
          component: () => import('@/views/user/UserProfile.vue')
        },
        {
          path: '/user/avatar',
          component: () => import('@/views/user/UserAvatar.vue')
        },
        {
          path: '/user/password',
          component: () => import('@/views/user/UserPassword.vue')
        }
      ]
    }
  ]
})

//登陆访问拦截
//返回值：
//1，undefined / true  直接放行
//2，false 拦截回from的地址页面
//3，具体路径 或 路径对象  拦截到对应的地址
//    '/login'    { name:'login' }
// router.beforeEach((to) => {
//   const userStore = useUserStore()
//   //如果没有token,且访问的是非登录页，拦截到登陆，
//   if (!userStore.token && to.path !== '/login') return '/login'
// })

export default router
